import numpy as np
def get_node_indices(obj, fdtd_domain):
    node_indices = {}
    # convert coordinates to node indices on the FDTD grid
    if 'min_x' in obj:
        node_indices["is"] = round((obj["min_x"] - fdtd_domain["min_x"])/fdtd_domain["dx"]) 
        node_indices["js"] = round((obj["min_y"] - fdtd_domain["min_y"])/fdtd_domain["dy"]) 
        node_indices["ks"] = round((obj["min_z"] - fdtd_domain["min_z"])/fdtd_domain["dz"]) 
        node_indices["ie"] = round((obj["max_x"] - fdtd_domain["min_x"])/fdtd_domain["dx"]) 
        node_indices["je"] = round((obj["max_y"] - fdtd_domain["min_y"])/fdtd_domain["dy"]) 
        node_indices["ke"] = round((obj["max_z"] - fdtd_domain["min_z"])/fdtd_domain["dz"]) 
    elif 'x' in obj:
        node_indices["is"] = round((obj["min_x"] - fdtd_domain["min_x"])/fdtd_domain["dx"])
        node_indices["js"] = round((obj["min_y"] - fdtd_domain["min_y"])/fdtd_domain["dy"])
        node_indices["ks"] = round((obj["min_z"] - fdtd_domain["min_z"])/fdtd_domain["dz"])
        node_indices["ie"] = node_indices["is"]
        node_indices["je"] = node_indices["js"]
        node_indices["ke"] = node_indices["ks"]
    return node_indices

def get_node_indices1(obj, node_coordinates_xe,node_coordinates_ye,node_coordinates_ze):
# convert coordinates to node indices on the FDTD grid
    node_indices = {}
    if 'min_x' in obj:
        node_indices["is"] = np.argmin(np.abs(obj["min_x"] - node_coordinates_xe)) + 1
        node_indices["js"] = np.argmin(np.abs(obj["min_y"] - node_coordinates_ye)) + 1
        node_indices["ks"] = np.argmin(np.abs(obj["min_z"] - node_coordinates_ze)) + 1
        node_indices["ie"] = np.argmin(np.abs(obj["max_x"] - node_coordinates_xe)) + 1
        node_indices["je"] = np.argmin(np.abs(obj["max_y"] - node_coordinates_ye)) + 1
        node_indices["ke"] = np.argmin(np.abs(obj["max_z"] - node_coordinates_ze)) + 1
    if 'x' in obj:
        node_indices["is"] = np.argmin(np.abs(obj["x"] - node_coordinates_xe)) + 1
        node_indices["js"] = np.argmin(np.abs(obj["y"] - node_coordinates_ye)) + 1
        node_indices["ks"] = np.argmin(np.abs(obj["z"] - node_coordinates_ze)) + 1
        
        node_indices["ie"] = node_indices["is"]
        node_indices["je"] = node_indices["js"]
        node_indices["ke"] = node_indices["ks"]
    return node_indices